package cn.wit.testalgorithms;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * 山脉数组的峰顶索引
 * @author 16604
 *
 */
public class DemoMountainsArray {
	public static void main(String[] args) {
		int[] a= {0,1,0};
		int[] b= {0,2,1,0};
		System.out.println(peakIndexInMountainArray(a));
		System.out.println(peakIndexInMountainArray(b));
	}
	public static int peakIndexInMountainArray(int[] A) {
		 Map<Integer,Integer> map = new HashMap<>();
		 for(int i = 0;i<A.length;i++) {
		 map.put(A[i], i);
		 }
		 Arrays.sort(A);
//		 System.out.println(map.get(A[A.length-1]));
		 return map.get(A[A.length-1]);
	}
}
